package com.xiaoyu.izf.controller;

import com.xiaoyu.izf.model.Region;
import com.xiaoyu.izf.service.RegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;


@Controller
@RequestMapping("/region")
public class RegionController extends BaseController {
	@Autowired
	private RegionService regionService;

	@RequestMapping("/cities")
	@ResponseBody
	public List<Region> regionCitys(HttpServletRequest request, int parentId) {
		if(parentId==0){
			List<Region> list = new ArrayList<>();
			Region region = new Region();
			region.setParentId(0);
			region.setRegionCode(""); 
			region.setRegionId(0);
			region.setRegionName("--市--");
			list.add(region);
			return list;
		}
		return regionService.cities(parentId);
	}

	@RequestMapping("/counties")
	@ResponseBody
	public List<Region> regionCounties(HttpServletRequest request, int parentId) {
		if(parentId==0){
			List<Region> list = new ArrayList<>();
			Region region = new Region();
			region.setParentId(0);
			region.setRegionCode("");
			region.setRegionId(0);
			region.setRegionName("--区县--");
			list.add(region);
			return list;
		}
		return regionService.cities(parentId);
	}

}
